﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace FOBTV.Web.FOBTV2011.en
{
    public partial class ChinaBank : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Double amount = Convert.ToDouble(GetRegistrationFeeInfo());
                this.LabUSValue.Text = Convert.ToString(amount);

            }
        }

        protected void BtnSubmit_Click(object sender, EventArgs e)
        {

            DateTime dt = DateTime.Now;
            string v_ymd = dt.ToString("yyyyMMdd"); // yyyyMMdd
            string timeStr = dt.ToString("HHmmss");
            Double amount = Convert.ToDouble(GetRegistrationFeeInfo());
            //Double amount = Convert.ToDouble(GetFeeRateInfo()) * Convert.ToDouble(GetRegistrationFeeInfo());
            //string  amountValue = Convert.ToString(amount);
            string amountValue = "1";
            UpdateInfo("2", "Prepare to submit fee");
            string v_oid= FOBTV.Web.MainClass.SessionState.CurrentUser.CustomerID+v_ymd + timeStr;
            Response.Redirect("send.aspx?v_oid=" + v_oid + "&v_amount=" + amountValue);
        }

        private string GetRegistrationFeeInfo()
        {
            string getRegistrationFee = "0";
            System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("..\\..\\DB\\FOBTVweb.mdb"));
            FOBTV.Web.MainClass.DBClass DBClassTmp = new FOBTV.Web.MainClass.DBClass();
            string sqlinfo = "SELECT   TOP 1 CustomerInfo.CustomerID, CustomerInfo.MemberShipID, RegistrationFee.RegistrationFee as RegistrationFee, ";
                sqlinfo += " RegistrationFee.RegistrationDate FROM  (CustomerInfo INNER JOIN ";
                sqlinfo += " RegistrationFee ON CustomerInfo.MemberShipID = RegistrationFee.MembershipID)";
                sqlinfo += " WHERE (RegistrationFee.RegistrationDate > #{0}#) AND (CustomerInfo.CustomerID = '{1}')";
                sqlinfo += " ORDER BY RegistrationFee.RegistrationDate";
                sqlinfo = string.Format(sqlinfo, System.DateTime.Now.ToShortDateString(), FOBTV.Web.MainClass.SessionState.CurrentUser.CustomerID);

             System.Data.DataSet ds = new System.Data.DataSet();
             ds = DBClassTmp.GetDataSet(sqlinfo, Conn);
            if (ds != null && ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                getRegistrationFee = ds.Tables[0].Rows[0]["RegistrationFee"].ToString();
            }
            return getRegistrationFee;
        }

        //private string GetFeeRateInfo()
        //{
        //    string getFeeRate = "0";
        //    System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("..\\..\\DB\\FOBTVweb.mdb"));
        //    FOBTV.Web.MainClass.DBClass DBClassTmp = new FOBTV.Web.MainClass.DBClass();
        //    string sqlinfo = "SELECT  Rate FROM  RateInfo";
        //    System.Data.DataSet ds = new System.Data.DataSet();
        //    ds = DBClassTmp.GetDataSet(sqlinfo, Conn);
        //    if (ds != null && ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        //    {
        //        getFeeRate = ds.Tables[0].Rows[0]["Rate"].ToString();
        //    }
        //    return getFeeRate;
        //}


        private bool UpdateInfo(string statusID, string StatusValue)
        {
            System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("..\\..\\DB\\FOBTVweb.mdb"));
            FOBTV.Web.MainClass.DBClass DBClassTmp = new FOBTV.Web.MainClass.DBClass();
            ArrayList sql = new ArrayList();
            sql.Clear();
            sql.Add(string.Format("UPDATE  CustomerInfo SET StatusID='{0}',Status='{1}',PayTime=#" + System.DateTime.Now.ToString() +
              "# WHERE (CustomerID ='" + FOBTV.Web.MainClass.SessionState.CurrentUser.CustomerID + "')", statusID, StatusValue));

            return DBClassTmp.ExcuteSQL(sql, Conn);

        }

        
    }
}